package com.shujia.flink.tf;

import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Demo04KeyBy {
    public static void main(String[] args) throws Exception {

        // KeyBy：将数据流进行分区，相同的Key会进入同一个并行度进行处理，Flink会给每个Key单独维护一个状态

        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(4);

        DataStreamSource<String> socketDS = env.socketTextStream("master", 8888);

        socketDS.keyBy(w -> w, Types.STRING).print();

        env.execute();


    }
}
